echo "==> k3s cluster settings:"
TOKEN=NEIwQ0IxMEUtNTA2MS00RE
API_SERVER="192.168.56.10"
FLANNEL_IFACE="enp0s8"
echo "    TOKEN: ${TOKEN}"
echo "    API_SERVER:${API_SERVER}"
echo "    FLANNEL_IFACE:${FLANNEL_IFACE}"

echo "==> disable firewall"
ufw disable

if [ $1 == "k3s-server" ]; then
    echo "==> install $1"
    curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | \
         INSTALL_K3S_MIRROR=cn \
         K3S_TOKEN=${TOKEN} \
         sh -s - server --flannel-iface ${FLANNEL_IFACE}
else
    echo "==> install $1"
    curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | \
         INSTALL_K3S_MIRROR=cn \
         K3S_URL=https://${API_SERVER}:6443 \
         K3S_TOKEN=${TOKEN} \
         sh -s - --flannel-iface ${FLANNEL_IFACE}
fi